package com.tian.view.custom

import android.content.Context
import android.graphics.Canvas
import android.graphics.Color
import android.graphics.Paint
import android.graphics.Rect
import android.util.AttributeSet
import android.widget.FrameLayout
import android.widget.OverScroller

/**
 * @author tiansongtao
 * @date 2023/1/4 18:05
 */
class TianCardView(context: Context, attrs: AttributeSet?, defStyleAttr: Int) :
        FrameLayout(context, attrs, defStyleAttr) {

    constructor(context: Context, attrs: AttributeSet?) : this(context, attrs, 0)
    constructor(context: Context) : this(context, null)

    init {
        setLayerType(LAYER_TYPE_SOFTWARE, null)
    }

    val paint = Paint().apply {
        color = Color.RED
        style = Paint.Style.FILL_AND_STROKE
        isAntiAlias = true
    }

    override fun onDraw(canvas: Canvas) {
        //super.onDraw(canvas)
        canvas.drawColor(Color.BLACK)
        val left = paddingLeft
        val top = paddingTop
        val right = paddingRight
        val bottom = paddingBottom
        val rect = Rect(left, top, width - right, height - bottom)


        paint.setShadowLayer(20f, 10f, 10f, Color.RED)
        canvas.drawRect(rect, paint)
        val draw = background
        draw.bounds = rect
        draw.draw(canvas)
    }
}